#include "gtlProperty.h"
#include "gtlGameObject.h"

namespace GTL { namespace Engine {


	void Property::UpdateFlags()
	{
		SetFlagsFlagsValue(0);
		for (int i=0; i<ModifierCount; i++)
		{
			Modifier* mod = &Modifiers[i];
			mod->InitFunction(mod, this);
		}
	}

	const Modifier* Property::GetModifier( int id ) const
	{
		for (int i=0; i<ModifierCount; i++)
		{
			if (Modifiers[i].Type == id)
				return &Modifiers[i];
		}
		return 0;
	}

	void AlertGameObject(void* go, void* sender, int ofwhat)
	{
		GameObject* g = (GameObject*)go;
		g->OnEvent(GameEvent::Make(Property::Event::Changed, sender, ofwhat));
	}

	namespace Is
	{
		void ReadOnly::Init( Modifier* mod, Property* bp )
		{
			bp->SetFlag(Property::ReadOnly);
		}

		void AlertedOnChange::Init( Modifier* mod, Property* bp )
		{
			bp->SetFlag(Property::AlertOnChange);
		}
	}
}}